/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cubelabs.nexus.controller;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import cubelabs.nexus.dto.SkillClassifiedDTO;
import cubelabs.nexus.entity.Bid;
import cubelabs.nexus.entity.ChatMessage;
import cubelabs.nexus.entity.SkillClassified;
import cubelabs.nexus.service.NexusService;

/**
 *
 * @author chaitanya
 */
@Controller
public class SkillClassifiedController {
	
	private static final Logger logger = LoggerFactory.getLogger(SkillClassifiedController.class);
	
	@Autowired
	private NexusService nexusService;
	
	@RequestMapping(value="/classified/{classifiedId}")
	public @ResponseBody SkillClassified getClassifiedInfoById(@PathVariable("classifiedId") Long classifiedId, HttpServletRequest request,HttpServletResponse response) throws Exception {
		return  nexusService.findClassifiedById(classifiedId, true);
	}
	
	@RequestMapping(value="/classified/")
	public ModelAndView getClassifiedInfo(HttpServletRequest request,HttpServletResponse response) throws Exception {
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("counsel");
		modelAndView.addObject("categories", nexusService.findAllCategories());
		return modelAndView;
	}
	
	@RequestMapping(value="/bid/{bidId}")
	public @ResponseBody Bid getBidInfo(@PathVariable("bidId") Long bidId, HttpServletRequest request,HttpServletResponse response) throws Exception {
		Bid bid  = nexusService.findBidById(bidId);
		return bid;
	}
	
	@RequestMapping(value="/user/{userId}/classifieds")
	public @ResponseBody List<SkillClassified> getClassifiedByUser(@PathVariable("userId") Long userId, HttpServletRequest request,HttpServletResponse response) throws Exception {
		return nexusService.findAllClassifiedsByUser(userId, true);
		
	}
	
	@RequestMapping(value="/category/{categoryId}/classifieds")
	public @ResponseBody List<SkillClassified> getClassifiedByCategory(@PathVariable("categoryId") Long categoryId, HttpServletRequest request,HttpServletResponse response) throws Exception {
		List<SkillClassified> skillClassifieds = nexusService.findAllClassifiedsByCategory(categoryId, true);
		return skillClassifieds; 
	}

	@RequestMapping(value="/classified/{classifiedId}/bids")
	public @ResponseBody List<Bid> getBidsByCategory(@PathVariable("classifiedId") Long classifiedId, HttpServletRequest request,HttpServletResponse response) throws Exception {
		return nexusService.findAllBidsByClassifiedId(classifiedId);
	}
	
	@RequestMapping(value="/user/{userId}/bids")
	public @ResponseBody List<Bid> getBidsByUser(@PathVariable("userId") Long userId, HttpServletRequest request,HttpServletResponse response) throws Exception {
		return nexusService.findBidsByUser(userId);
	}
	
	@RequestMapping(value="/bids/{bidId}/messages")
	public @ResponseBody List<ChatMessage> fetchAllMessages(@PathVariable("bidId") Long bidId) {
		return nexusService.fetchMessagesByBid(bidId);
	}
	
}
